﻿using System.Web.Mvc;
using Yyyg.IBLL;
using Yyyg.WebUI.Models;

namespace Yyyg.WebUI.Controllers
{
    public class UserRegController : Controller
    {
        IMemberService users;
        public UserRegController(IMemberService users)
        {
            this.users = users;
        }

        // GET: UserReg
        [HttpGet]
        public ActionResult Reg()
        {
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Reg(UserRegVM info)
        {
            if (ModelState.IsValid)
            {
                if (!users.HasUser(info.Mobel))
                {
                    var user = users.AddUser(info.Mobel, info.Pwd);
                    ViewBag.UserName = user.Petname;
                    ViewBag.RegRank = users.Count();
                    return View("RegSucc");
                }
            }
            return View(info);
        }

        public JsonResult HasMobel(string Mobel)
        {
            return Json(!users.HasUser(Mobel), JsonRequestBehavior.AllowGet);
        }
    }
}